﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TKToXML.Models
{
    public class VanDon : BaseChungTu, IBaseChungTu
    {           
        public virtual Agent Agent { get; set; }
        public virtual Importer Importer { get; set; }
        public virtual DeclarationDocument DeclarationDocument { get; set; }

        public virtual string SoVanDon { get; set; }
        public virtual DateTime NgayVanDon { get; set; }
        public virtual string MaNuocPhatHanhVanDon { get; set; }
        public virtual string TenPhuongTienVanTai { get; set; }
        public virtual string SoHieuChuyenDi { get; set; }
        public virtual DateTime NgayKhoiHanh { get; set; }
        public virtual string QuocTichPTVT { get; set; }
        public virtual string TenHangVanTai { get; set; }
        public virtual string TenNguoiGuiHang { get; set; }
        public virtual string TenNguoiNhanHang { get; set; }
        public virtual string TenNguoiDuocThongBao { get; set; }
        public virtual string CangXepHang { get; set; }
        public virtual DateTime NgayPhuongTienDi { get; set; }
        public virtual string CangDoHang { get; set; }
        public virtual DateTime NgayPhuongTienDen { get; set; }
        public virtual string CangDich { get; set; }
        public virtual int TongSoKien { get; set; }

        /// <summary>
        /// Số tiếp nhận
        /// </summary>
        public virtual int CustomsReference { get; set; }
        /// <summary>
        /// Ngày nhận được số tiếp nhận
        /// </summary>
        public virtual DateTime NgayNhanSoTiepNhan { get; set; }
        
        public virtual string ToXML()
        {
            //Thong thuong khong khai bao van don doc lap, ma khai bao kem voi to khai
            string result = "";
                //result += "<Declaration>";            
                //result += "<issuer>" + Type + "</issuer>";
                //result += "<reference>" + Reference + "</reference>";
                //result += "<issue>" + IssueDate.ToString("yyyy-MM-dd HH:mm:ss") + "</issue>";//2010-08-17 16:40:00
                //result += "<function>" + (int)MessageFuntion.KhaiBao + "</function>"; 
                ////Nơi khai báo không bắt buộc khai
                ////result += "<issueLocation>" + "" + "</issueLocation>";
                ////So tiep nhan
                //result += "<customsReference>" + CustomsReference.ToString() + "</customsReference>"; 
                ////Ngay nhan duoc so tiep nhan
                //result += "<acceptance>" + NgayNhanSoTiepNhan.ToString("yyyy-MM-dd HH:mm:ss") + "</acceptance>";                
                //result += "<declarationOffice>" + MaHQ +"</declarationOffice>";
                //result += Agent.ToXML();
                result += "<BillOfLadings>"; 
                    result += "<BillOfLading>";                    
                        result += "<reference>" + SoVanDon + "</reference>";
                        result += "<issue>" + NgayVanDon.ToString("yyyy-MM-dd") + "</issue>";
                        result += "<issueLocation>" + MaNuocPhatHanhVanDon + "</issueLocation>";
                        result += "<BorderTransportMeans>";
                            //Khong bat buoc khai
                            //result += "<identity>" + SoHieuPhuongTienVanTai + "</identity>";
                            result += "<identification>" + TenPhuongTienVanTai + "</identification>";
                            result += "<journey>" + SoHieuChuyenDi + "</journey>";
                            result += "<departure>" + NgayKhoiHanh.ToString("yyyy-MM-dd") + "</departure>";
                            result += "<registrationNationality>" + QuocTichPTVT + "</registrationNationality>";                        
                        result += "</BorderTransportMeans>";
                        result += "<Carrier>";                        
                            result += "<name>" + TenHangVanTai + "</name>";                        
                        result += "</Carrier>";
                        result += "<Consignment>";
                            result += "<Consignor>";
                                result += "<name>" + TenNguoiGuiHang + "</name>";
                            result += "</Consignor>";
                            result += "<Consignee>";
                                result += "<name>" + TenNguoiNhanHang + "</name>";
                            result += "</Consignee>";
                            result += "<NotifyParty>";
                                result += "<name>" + TenNguoiDuocThongBao + "</name>";
                            result += "</NotifyParty>";
                            result += "<LoadingLocation>";
                                result += "<name>" + CangXepHang + "</name>";
                                result += "<loading>" + NgayPhuongTienDi.ToString("yyyy-MM-dd") + "</loading>";
                            result += "</LoadingLocation>";
                            result += "<UnloadingLocation>";
                                result += "<name>" + CangDoHang + "</name>";
                                result += "<arrival>" + NgayPhuongTienDen.ToString("yyyy-MM-dd") + "</arrival>";
                            result += "</UnloadingLocation>";
                            result += "<DeliveryDestination>";
                                result += "<line>" + CangDich + "</line>";
                            result += "</DeliveryDestination>";
                            result += "<ConsignmentItemPackaging>";
                                result += "<quantity>" + TongSoKien + "</quantity>";
                                //Loai kien khong dung nhung bat buoc phai khai
                                result += "<type>" + "1" + "</type>";
                            result += "</ConsignmentItemPackaging>";
                        result += "</Consignment>";

                    
                    result += "</BillOfLading>";
                result += "</BillOfLadings>";
            //result += "</Declaration>";            

            return result;
        }
    }
}
